@extends('shop::layouts.master')
@section('title') 商品列表 @endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-tab">
                    <ul class="layui-tab-title">
                        <li data-type="" @if($search['type']=='') class="layui-this" @endif>全部商品</li>
                        <li data-type="1" @if($search['type']==1) class="layui-this" @endif>普通商品</li>
                       {{-- <li data-type="2" @if($search['type']==2) class="layui-this" @endif>积分商品</li>--}}
                        <li data-type="3" @if($search['type']==3) class="layui-this" @endif>活动商品</li>
                    </ul>
                </div>

                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-input-inline layui-show-xs-block">
                                <input type="text" name="name" placeholder="商品名称" value="{{$search['name']}}" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-show-xs-block">
                                <select name="cate_id">
                                    <option value="">选择分类</option>
                                    @if($arr_data['cate'])
                                        @foreach($arr_data['cate'] as $k => $v)
                                            <option value="{{$v['id']}}" @if($search['cate_id']==$v['id']) selected @endif>{{$v['name']}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </div>
                            <div class="layui-input-inline layui-show-xs-block">
                                <select name="status">
                                    <option value="">选择状态</option>
                                    <option value="1" @if($search['status']==1) selected @endif>已上架</option>
                                    <option value="2" @if($search['status']==2) selected @endif>已下架</option>
                                </select>
                            </div>
                            <input type="hidden" name="type" value="{{$search['type']}}">
                            <div class="layui-input-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                    <i class="layui-icon">&#xe615;</i>
                                </button>
                                <button class="layui-btn" onclick="location.reload()">
                                    <i class="layui-icon layui-icon-refresh"></i>
                                </button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body layui_overflow_y ">
                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>商品名称</th>
                                <th>副标题</th>
                                <th>所属分类</th>
                                <th>商品类型</th>
                                <th>是否推荐</th>
                                <th>状态</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if(!empty($arr_data['data']))
                                @foreach($arr_data['data'] as $key=>$value)
                                    <tr>
                                        <td>{{$value['id']}}</td>
                                        <td>{{$value['name']}}</td>
                                        <td>{{$value['title']}}</td>
                                        <td>{{$value['cate']['name']}}</td>
                                        <td>@if($value['type'] == 1)
                                                普通商品
                                            @elseif($value['type'] == 2)
                                                积分商品
                                            @elseif($value['type'] == 3)
                                                活动商品
                                            @endif
                                        </td>
                                        <td>{{$value['is_recommend'] == 1?"是":"否"}}</td>
                                        <td>
                                            <input type="checkbox" name="switch" data_attr='{"id":"{{$value['id']}}","field_name":"status","url":"{{route("shop_goods_changeState")}}"}' lay-text="上架|下架" lay-filter="change_state" @if($value['status'] == 1) checked @endif lay-skin="switch">
                                        </td>
                                        <td>{{$value['created_at']}}</td>
                                        <td class="td-manage">
                                            <a title="编辑" class="layui-btn" onclick="xadmin.open('编辑','{{route('shop_goods_edit',['id'=>$value['id']])}}',$(window).width(),$(window).height())" href="javascript:;">
                                                编辑
                                            </a>
                                            <a title="删除" class="ajax_member_del layui-btn layui-btn-danger" data-href="{{route('shop_goods_del',['id'=>$value['id']])}}" data-title="确定删除吗？请谨慎操作" href="javascript:;">
                                                删除
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach
                            @else
                                <td colspan="66" align="center">暂无数据</td>
                            @endif
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{$arr_data['page_link']}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection

@section('tab_js')
    <script type="text/javascript">
        layui.use(['form'], function(){
            var form = layui.form;
            form.render();
            //监听指定开关-修改状态
            form.on('switch(change_state)',function(){
                change_state(this);
            });
        });

        $(document).on('click', '.layui-tab-title li', function () {
            var type = $(this).attr('data-type');
            var data = '?type='+type;

            location_redirect('shop-goods-index'+data);
        });
    </script>
@endsection




